package cn.sunshine.framework.aop.framework.adapter;

import cn.sunshine.framework.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @Description cn.sunshine.framework.aop.framework.adapter
 * @Author Mokairui
 * @Since 2021/12/22
 */
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {

    private MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        this.advice.before(invocation.getMethod(),
                invocation.getArguments(),
                invocation.getThis());
        return invocation.proceed();
    }
}
